<html lang="en-US" xmlns:th = "http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../../css/common.css">
<script src="../../js/jquery.js"></script>
<body>

<form action="" method="post" class="layui-form layui-form-pane">

    <input type="text" id="Id" name="Id" th:value="${equipment.getId()}" hidden = "hidden" >


    <div class="layui-form-item">
        <label for="name" class="layui-form-label">
            设备名称
        </label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${equipment.getName()}" >
        </div>
    </div>
    <div class="layui-form-item">
        <label for="price" class="layui-form-label">
            价格
        </label>
        <div class="layui-input-block">
            <input type="text" id="price" name="price"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input"  th:value="${equipment.getPrice()}">
        </div>
    </div>

    <div class="layui-form-item">
        <label for="comment" class="layui-form-label">
            详情
        </label>
        <div class="layui-input-block">
            <input type="text" id="comment" name="comment"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${equipment.getComment()}">
        </div>
    </div>


    <div class="layui-form-item">
        <label for="type" class="layui-form-label">
            类别
        </label>
        <div class="layui-input-block">
            <select name="type" lay-filter="type" id="type">
                <option value="0">休闲</option>
                <option value="1">益智</option>
                <option value="2">沉浸式</option>
                <option value="3">pvp</option>
                <option value="4">卡牌</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label for="used" class="layui-form-label">
            是否有人使用
        </label>
        <div class="layui-input-block" id="used" >
            <input type="radio" name="used" th:value="1" title="正在使用" th:checked="${equipment.getUsed()==1}">
            <input type="radio" name="used" th:value="0" title="无人使用" th:checked="${equipment.getUsed()==0}">
            <!--<input type="text" th:value="${equipment.getUsed()}">-->
        </div>
    </div>
    <div class="layui-form-item">
        <label for="used" class="layui-form-label">
            设备是否损坏
        </label>
        <div class="layui-input-block" id="damaged" >
            <input type="radio" name="damaged" th:value="1" title="没坏" th:checked="${equipment.getDamage()==1}">
            <input type="radio" name="damaged" th:value="0" title="坏了" th:checked="${equipment.getDamage()==0}">
            <!--<input type="text" th:value="${equipment.getUsed()}">-->
        </div>
    </div>

    <!--<div class="layui-form-item">-->
        <!--<label for="number" class="layui-form-label">-->
            <!--数量-->
        <!--</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="text" id="number" name="number"-->
                   <!--lay-verify="required" lay-vertype="tips"-->
                   <!--autocomplete="off" class="layui-input" th:value="${equipment.getNumber()}">-->
        <!--</div>-->
    <!--</div>-->

    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left:0;text-align:center;">

            <button class="layui-btn layui-btn-normal"  type="button" onclick="toAjax()">修改</button>
        </div>
    </div>
</form>
<script src="../../layui/layui.js"></script>
<script src="../../js/common.js"></script>
<script>

    layui.config({
        base: '/layui/extend/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use(['form', 'layer', 'formSelects', 'dtree'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer

    });
    function toAjax() {
        var a = document.getElementsByName("used");
        var used = 0;
        for(var   i=0;   i<a.length;   i++)    {
            if(a[i].checked){
                used = a[i].value
            }
        }
        var dama = document.getElementsByName("damaged");
        var damaged = 0;
        for(var   i=0;   i<dama.length;   i++)    {
            if(dama[i].checked){
                damaged = dama[i].value
            }
        }
        $.ajax({
            type: "post",
            url: "/equipment/update/",
            data: {id:$("#Id").val(),name:$("#name").val(),price:$("#price").val()
                ,comment:$("#comment").val(),used:used,type:$("#type option:selected").val(),
                damage:damaged},
            dataType: "json",
            success: function (data) {
                if (data.code == '201') {
                    layer.msg("失败", {icon: 5});//失败的表情

                    return;
                } else if (data.code == '0') {
                    layer.msg("成功", {
                        icon: 6,//成功的表情
                        time: 1000 //1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        location.reload();
                    })
                };
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        });
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    };


</script>

</body>
</html>